<!--
 * @Author: xuzehan h935351619@163.com
 * @Date: 2024-07-22 14:37:57
 * @LastEditors: xuzehan h935351619@163.com
 * @LastEditTime: 2024-11-25 14:39:02
 * @FilePath: \linshi\src\views\EquipmentControl\FrequencyConverter.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div>
    <!-- 按钮区域 -->
    <div class="table-page-search-wrapper">
      <a-form-model layout="inline" :model="searchForm">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="群解调设备(主)开始工作" prop="symbolRate">
              <a-button type="primary" @click="onStart" :disabled="startBtnDisabled">启动</a-button>
              <span style="color: white;margin-left: 10px;">说明:主设备进入工作状态，接收数据，备设备进入待机状态</span>
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </div>
    <div class="groupDemodulatorBox">
      <div class="groupDemodulatorBox_card">
        <a-card title="MAC层至物理层参数设置" :bordered="false" class="cardItem">
          <!-- <a slot="extra" href="#">配置</a> -->
          <a-form-model :model="form" :label-col="labelCol" :wrapper-col="wrapperCol">
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="输入选择">
                  <a-select v-model="form.inputSelect" placeholder="请选择">
                    <a-select-option value="00">
                      L频段
                    </a-select-option>
                    <a-select-option value="01">
                      ka频段
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="inputSelect()" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="工作模式">
                  <a-select v-model="form.PilotWorkingMode" placeholder="请选择">
                    <a-select-option value="1">
                      工作模式
                    </a-select-option>
                    <a-select-option value="2">
                      测试模式
                    </a-select-option>
                  </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(3)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="物理层DCPR接收系统重置">
                  <a-button type="primary" @click="handleSend(1)" :disabled="!startBtnDisabled"> 重置 </a-button>
                </a-form-model-item>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="物理层测试子系统重置">
                  <a-button type="primary" @click="handleSend(2)" :disabled="!startBtnDisabled"> 重置 </a-button>
                </a-form-model-item>
              </a-col>
            </a-row>

            <!-- <a-row>
            <a-col :span="20">
              <a-form-model-item label="导频信号开关">
                <a-select v-model="form.PilotSignalSwitch" placeholder="请选择">
                  <a-select-option value="0">
                    关
                  </a-select-option>
                  <a-select-option value="1">
                    开
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click='handleSend(4)'> 确定 </a-button>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="20">
              <a-form-model-item label="测试模式下的工作模式">
                <a-select v-model="form.WorkModeTestingMode" placeholder="请选择">
                  <a-select-option value="1">
                    导频模式
                  </a-select-option>
                  <a-select-option value="2">
                    轮询模式
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click='handleSend(5)'> 确定 </a-button>
            </a-col>
          </a-row> -->
            <!-- <a-row>
            <a-col :span="20">
              <a-form-model-item label="国内测试子系统通道号">
                <a-input-number
                  :style="{ width: '100%' }"
                  :step="1"
                  :min="1"
                  :max="380"
                  v-model="form.channelNumber"
                  placeholder="请输入(1~400)"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click="handleSend(6)"> 确定 </a-button>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="20">
              <a-form-model-item label="国际测试子系统通道号">
                <a-input-number
                  :style="{ width: '100%' }"
                  :step="1"
                  :min="1"
                  :max="33"
                  v-model="form.channelNumber"
                  placeholder="请输入(1~400)"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click="handleSend(6)"> 确定 </a-button>
            </a-col>
          </a-row> -->
            <!--     特征码 最少5个字节: 前4个字节结构是(21bit的平台唯一码, 再补上11bit的0), 然后跟数据-->
            <!-- <a-row>
            <a-col :span="20">
              <a-form-model-item label="测试子系统符号速率">
                <a-select v-model="form.symbolRate" placeholder="请选择">
                  <a-select-option value="1">
                    300
                  </a-select-option>
                  <a-select-option value="2">
                    450
                  </a-select-option>
                  <a-select-option value="3">
                    900
                  </a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click='handleSend(7)'> 确定 </a-button>
            </a-col>
          </a-row>
          <a-row>
            <a-col :span="20">
              <a-form-model-item label="特征码">

                <a-textarea placeholder="最长218字节" :maxLength='444' v-model="form.ErrorSourceData" :rows="4" />
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button type="primary" @click='handleSend(8)'> 确定 </a-button>
            </a-col>
          </a-row> -->
          </a-form-model>
        </a-card>
        <a-card title="通道板参数控制" :bordered="false" class="cardItem">
          <a-form-model :model="formc" :label-col="labelCol1" :wrapper-col="wrapperCol1">
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="下行通道1（国内）衰减器1">
                  <a-input v-model="formc.attenuator1" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(9)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="下行通道1（国内）衰减器2">
                  <a-input v-model="formc.attenuator2" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(10)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="下行通道1（国际）衰减器1">
                  <a-input v-model="formc.attenuator3" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(11)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="下行通道1（国际）衰减器2">
                  <a-input v-model="formc.attenuator4" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(12)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="上行通道 衰减器1">
                  <a-input v-model="formc.attenuator5" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(13)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
            <a-row>
              <a-col :span="20">
                <a-form-model-item label="上行通道 衰减器2">
                  <a-input v-model="formc.attenuator6" placeholder="请输入" />
                </a-form-model-item>
              </a-col>
              <a-col :span="4">
                <a-button type="primary" @click="handleSend(14)" :disabled="!startBtnDisabled"> 确定 </a-button>
              </a-col>
            </a-row>
          </a-form-model>
        </a-card>
        <!--      <a-card title="网络设置" style="width:25%;border-bottom: 3px solid #17dcff" :bordered="false">
        <a slot="extra" href="#" @click="handleSendPackage('networkControl')">配置</a>
        <a-form-model ref="ruleForm" :rules="rules" :model="formB" :label-col="labelCol" :wrapper-col="wrapperCol">
          <a-form-model-item label="TCP端口">
            <a-input-number
              :style="{ width: '100%' }"
              :min="0"
              :max="65532"
              v-model="formB.tcpPort"
              placeholder="请输入0 ~ 65532"
            />
          </a-form-model-item>
          <a-form-model-item label="IP地址" prop="IPaddress">
            <a-input v-model="formB.IPaddress" placeholder="请输入" />
          </a-form-model-item>
          <a-form-model-item label="网关" prop="gateway">
            <a-input v-model="formB.gateway" placeholder="请输入" />
          </a-form-model-item>
          <a-form-model-item label="子网掩码" prop="subnetMask">
            <a-input v-model="formB.subnetMask" placeholder="请输入" />
          </a-form-model-item>
          <a-form-model-item label="MAC地址" prop="MACaddress">
            <a-input v-model="formB.MACaddress" placeholder="请输入XX:XX:XX:XX:XX:XX(十六进制)" />
          </a-form-model-item>
        </a-form-model>
      </a-card>-->
      </div>

      <a-card title="国内频偏测试" style="width: 100%" :bordered="false">
        <!-- <div class="testCard">
          <div class="testCard_item">
            <span>通道号:</span>
            <a-input-number style="margin-top: 3px;margin-left: 5px;" v-model="testForm.startTdh" placeholder="输入1-380" ></a-input-number>
          </div>
          <div class="testCard_item" style="margin-left: 30px;">
            <span>符号速率:</span>
            <span style="margin-left: 5px;">{{ testForm.symbolRate }}sps</span>
          </div>
          <div class="testCard_item" style="margin-left: 30px;">
            <a-button type="primary" @click="handleStart()" :disabled="testBtnDisabled">开始</a-button>
            <span style="color: white; margin-left: 20px;">{{ countDown }}</span>
          </div>
        </div> -->
        <a-form-model
          :model="testForm"
          :label-col="labelCol"
          :wrapper-col="wrapperCol"
          :rules="testRules"
          ref="testForm"
        >
          <a-row>
            <a-col :span="4">
              <a-form-model-item label="通道号" prop="startTdh">
                <a-input-number
                  style="margin-top: 3px;"
                  v-model="testForm.startTdh"
                  placeholder="输入1-380"
                ></a-input-number>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-form-model-item label="符号速率" prop="symbolRate">
                <a-input
                  id="spsInput"
                  v-model="testForm.symbolRate"
                  disabled
                  style="width: 50%;"
                  suffix="sps"
                ></a-input>
              </a-form-model-item>
            </a-col>
            <a-col :span="4">
              <a-button
                style="margin-top: 4px;"
                type="primary"
                @click="handleStart()"
                :disabled="testBtnDisabled || !startBtnDisabled"
                >开始</a-button
              >
              <span v-if="loading" style="color: white;">正在发起测试...</span>
              <span v-else style="color: white; margin-left: 20px;">{{ countDown }}</span>
            </a-col>
          </a-row>
        </a-form-model>
      </a-card>
    </div>
  </div>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import { postAction } from '../../../api/manage'
// import { WebsocketMixin } from '../../../mixins/WebsocketMixin'
export default {
  // mixins: [WebsocketMixin],
  data() {
    let validateIPaddress = (rule, value, callback) => {
      const regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
      // return regex.test(value);
      console.log(regex.test(value), '校验')
      if (!regex.test(value)) {
        callback(new Error('ip地址格式错误'))
      } else {
        callback()
      }
    }
    let validateGateway = (rule, value, callback) => {
      const regex = /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/
      // return regex.test(value);
      if (!regex.test(value)) {
        callback(new Error('网关地址格式错误'))
      } else {
        callback()
      }
    }
    let validateMACaddress = (rule, value, callback) => {
      const regex = /^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/
      // return regex.test(value);
      if (!regex.test(value)) {
        callback(new Error('MAC地址格式错误'))
      } else {
        callback()
      }
    }
    let validateSubnetMask = (rule, value, callback) => {
      const regex = /^((255\.255\.255\.(0|128|192|224|240|248|252|254|255))|(255\.255\.(0|128|192|224|240|248|252|254|255)\.0)|(255\.(0|128|192|224|240|248|252|254|255)\.0\.0)|((0|128|192|224|240|248|252|254|255)\.0\.0\.0))$/
      // return regex.test(value);
      if (!regex.test(value)) {
        callback(new Error('子网掩码格式错误'))
      } else {
        callback()
      }
    }
    return {
      labelCol: { span: 10 },
      wrapperCol: { span: 14 },
      labelCol1: { span: 14 },
      wrapperCol1: { span: 10 },
      form: {
        // PilotWorkingMode:'1',
        // PilotSignalSwitch:'0',
        // WorkModeTestingMode:'2',
        channelNumber: '34',
        // symbolRate:'1',
        ErrorSourceData: ''
      },
      formc: {
        attenuator1: '',
        attenuator2: '',
        attenuator3: '',
        attenuator4: '',
        attenuator5: '',
        attenuator6: ''
      },
      formB: {},
      url: {
        sendPackage: '/channel/nmcChannelInfo/sendPackage',
        getByChannelCode: '/attr/nmcAttr/getByChannelCode',
        add: '/plan/qlTestPlan/add',
        edit: 'nmc/activeInfo/edit',
        list: 'nmc/activeInfo/list',
        rateList: '/dcpr/dcprPassagewaySlInit/list', //获取通道信息来下发速率
        modifySl: 'dcpr/dcprPassagewaySlTemp/modifySl' //速率下发
      },
      rules: {
        gateway: [{ validator: validateGateway, trigger: 'blur' }],
        IPaddress: [{ validator: validateIPaddress, trigger: 'blur' }],
        MACaddress: [{ validator: validateMACaddress, trigger: 'blur' }],
        subnetMask: [{ validator: validateSubnetMask, trigger: 'blur' }]
      },
      testForm: {
        symbolRate: '900'
      },
      countDown: '', //倒计时
      testBtnDisabled: false, //控制开始测试 按钮
      searchForm: {},
      testRules: {
        startTdh: [
          { required: true, message: '请输入通道号,必须为正整数!' },
          { pattern: /^[1-9]\d*$/, message: '通道号必须为正整数!' }
        ]
      },
      loading: false,
      startBtnDisabled: false,
      datalist: [],
      websock: null,
      isDestroying: false
      // optionsA:[
      //   {
      //     id:1,
      //     label:'测试子系统启动指令',
      //     packageCode:'',
      //     nmcPackageGridValues:[]
      //   },
      //   {
      //     id:2,
      //     label:'物理层解调系统重置指令',
      //     packageCode:'',
      //     nmcPackageGridValues:[]
      //   },
      //   {
      //     id:3,
      //     label:'导频工作模式',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-导频工作模式",
      //               "packageGridValue":this.decToHex(this.form.PilotWorkingMode)
      //             }
      //           ]
      //   },
      //   {
      //     id:4,
      //     label:'导频信号开关',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-导频信号开关",
      //               "packageGridValue":this.decToHex(this.form.PilotSignalSwitch)
      //             }
      //           ]
      //   },
      //   {
      //     id:5,
      //     label:'测试模式下的工作模式',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-测试模式下的工作模式",
      //               "packageGridValue":this.decToHex(this.form.WorkModeTestingMode)
      //             }
      //           ]
      //   },
      //   {
      //     id:6,
      //     label:'测试子系统通道号',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-测试子系统通道号",
      //               "packageGridValue":this.decToHex(this.form.channelNumber)
      //             }
      //           ]
      //   },
      //   {
      //     id:7,
      //     label:'测试子系统符号速率',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-测试子系统符号速率",
      //               "packageGridValue":this.decToHex(this.form.symbolRate)
      //             }
      //           ]
      //   },
      //   {
      //     id:8,
      //     label:'误码源数据',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-误码源数据",
      //               "packageGridValue":this.decToHex(this.form.ErrorSourceData)
      //             }
      //           ]
      //   },
      //   {
      //     id:9,
      //     label:'下行通道1（国内）衰减器1',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-下行通道1（国内）衰减器1",
      //               "packageGridValue":this.decToHex(this.formc.attenuator1*100)
      //             }
      //           ]
      //   },
      //   {
      //     id:10,
      //     label:'下行通道1（国内）衰减器2',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-下行通道1（国内）衰减器2",
      //               "packageGridValue":this.decToHex(this.formc.attenuator2*100)
      //             }
      //           ]
      //   },
      //   {
      //     id:11,
      //     label:'下行通道1（国际）衰减器1',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-下行通道1（国际）衰减器1",
      //               "packageGridValue":this.decToHex(this.formc.attenuator3*100)
      //             }
      //           ]
      //   },
      //   {
      //     id:12,
      //     label:'下行通道1（国际）衰减器2',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-下行通道1（国际）衰减器2",
      //               "packageGridValue":this.decToHex(this.formc.attenuator4*100)
      //             }
      //           ]
      //   },
      //   {
      //     id:13,
      //     label:'上行通道 衰减器1',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-上行通道 衰减器1",
      //               "packageGridValue":this.decToHex(this.formc.attenuator5*100)
      //             }
      //           ]
      //   },
      //   {
      //     id:14,
      //     label:'上行通道 衰减器2',
      //     packageCode:'',
      //     nmcPackageGridValues:[
      //             {
      //               "gridCode": "022-上行通道 衰减器2",
      //               "packageGridValue":this.decToHex(this.formc.attenuator6*100)
      //             }
      //           ]
      //   },
      // ],
    }
  },
  created() {
    this.paramInit()
  },
  mounted() {
    this.getList()
    // this.initWebSocket()
    this.getListData()
  },
  // beforeDestroy() {
  //   console.log('离开')
  //   this.websocketOncloseForDestroy() // 👈 用这个方法
  // },
  methods: {
    inputSelect() {
      let data = {
        channelCode: '群解调',
        nmcPackageGridValues: [
          {
            gridCode: '622-输入选择',
            packageGridValue: this.form.inputSelect
          }
        ],
        packageCode: '622-解调器-输入选择设置'
      }
      httpAction(this.url.sendPackage, data, 'post').then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    paramInit() {
      let temp = {
        channelCode: '群解调'
      }
      getAction(this.url.getByChannelCode, temp).then(res => {
        if (res.success) {
          res.result.forEach(i => {
            if (i.attrName === '导频信号开关') {
              this.$set(this.form, 'PilotSignalSwitch', i.parseValue)
            } else if (i.attrName === '导频工作模式') {
              this.$set(this.form, 'PilotWorkingMode', i.parseValue)
            } else if (i.attrName === '下行通道1(国内)衰减器1') {
              this.$set(this.formc, 'attenuator1', i.parseValue)
            } else if (i.attrName === '下行通道1(国内)衰减器2') {
              this.$set(this.formc, 'attenuator2', i.parseValue)
            } else if (i.attrName === '下行通道1(国际)衰减器1') {
              this.$set(this.formc, 'attenuator3', i.parseValue)
            } else if (i.attrName === '下行通道1(国际)衰减器2') {
              this.$set(this.formc, 'attenuator4', i.parseValue)
            } else if (i.attrName === '上行通道衰减器1') {
              this.$set(this.formc, 'attenuator5', i.parseValue)
            } else if (i.attrName === '上行通道衰减器2') {
              this.$set(this.formc, 'attenuator6', i.parseValue)
            } else if (i.attrName === '下行通道1(国际)衰减器1') {
              this.$set(this.form, 'attenuator3', i.parseValue)
            } else if (i.attrName === '下行通道1(国际)衰减器1') {
              this.$set(this.form, 'attenuator3', i.parseValue)
            } else if (i.attrName === '下行通道1(国际)衰减器1') {
              this.$set(this.form, 'attenuator3', i.parseValue)
            } else if (i.attrName === 'ipdz') {
              this.$set(this.formB, 'IPaddress', i.parseValue)
            } else if (i.attrName === 'wg') {
              this.$set(this.formB, 'gateway', i.parseValue)
            } else if (i.attrName === 'zwym') {
              this.$set(this.formB, 'subnetMask', i.parseValue)
            } else if (i.attrName === 'macdz') {
              this.$set(this.formB, 'MACaddress', i.parseValue)
            } else if (i.attrName === 'tcpdk') {
              this.$set(this.formB, 'tcpPort', i.parseValue)
            }
          })
        }
      })
    },
    handleSend(val) {
      let optionsA = [
        {
          id: 1,
          label: '测试子系统启动指令',
          packageCode: '602-解调器-MAC层至物理层参数设置-物理层测试子系统重置指令',
          nmcPackageGridValues: []
        },
        {
          id: 2,
          label: '物理层解调系统重置指令',
          packageCode: '601-解调器-MAC层至物理层参数设置-物理层DCPR接收系统重置指令',
          nmcPackageGridValues: []
        },
        {
          id: 3,
          label: '导频工作模式',
          packageCode: '603-解调器-MAC层至物理层参数设置-导频工作模式',
          nmcPackageGridValues: [
            {
              gridCode: '603-指令字段内容',
              packageGridValue: this.decToHex(this.form.PilotWorkingMode)
            }
          ]
        },
        {
          id: 4,
          label: '导频信号开关',
          packageCode: '604-解调器-MAC层至物理层参数设置-导频信号开关',
          nmcPackageGridValues: [
            {
              gridCode: '604-指令字段内容',
              packageGridValue: this.decToHex(this.form.PilotSignalSwitch)
            }
          ]
        },
        {
          id: 5,
          label: '测试模式下的工作模式',
          packageCode: '605-解调器-MAC层至物理层参数设置-配置测试模式下的工作模式',
          nmcPackageGridValues: [
            {
              gridCode: '605-指令字段内容',
              packageGridValue: this.decToHex(this.form.WorkModeTestingMode)
            }
          ]
        },
        {
          id: 6,
          label: '测试子系统通道号',
          packageCode: '606-解调器-MAC层至物理层参数设置-配置测试子系统通道号',
          nmcPackageGridValues: [
            {
              gridCode: '606-指令字段内容',
              packageGridValue: this.decToHex(this.form.channelNumber)
            }
          ]
        },
        {
          id: 7,
          label: '测试子系统符号速率',
          packageCode: '607-解调器-MAC层至物理层参数设置-配置测试子系统符号速率',
          nmcPackageGridValues: [
            {
              gridCode: '607-指令字段内容',
              packageGridValue: this.decToHex(this.form.symbolRate)
            }
          ]
        },
        {
          id: 8,
          label: '特征码',
          packageCode: '608-解调器-MAC层至物理层参数设置-轮询模式中测试误码率',
          nmcPackageGridValues: [
            {
              gridCode: '608-指令字段内容',
              packageGridValue: this.form.ErrorSourceData
            },
            {
              gridCode: '608-指令字段内容长度',
              packageGridValue: this.decToHex(this.form.ErrorSourceData.length / 2)
            }
          ]
        },
        {
          id: 9,
          label: '下行通道1（国内）衰减器1',
          packageCode: '609-解调器-通道板参数控制-下行通道1(国内)衰减器1',
          nmcPackageGridValues: [
            {
              gridCode: '609-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator1 * 100, 4)
            }
          ]
        },
        {
          id: 10,
          label: '下行通道1（国内）衰减器2',
          packageCode: '610-解调器-通道板参数控制-下行通道1(国内)衰减器2',
          nmcPackageGridValues: [
            {
              gridCode: '610-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator2 * 100, 4)
            }
          ]
        },
        {
          id: 11,
          label: '下行通道1（国际）衰减器1',
          packageCode: '611-解调器-通道板参数控制-下行通道1(国际)衰减器1',
          nmcPackageGridValues: [
            {
              gridCode: '611-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator3 * 100, 4)
            }
          ]
        },
        {
          id: 12,
          label: '下行通道1（国际）衰减器2',
          packageCode: '612-解调器-通道板参数控制-下行通道1(国际)衰减器2',
          nmcPackageGridValues: [
            {
              gridCode: '612-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator4 * 100, 4)
            }
          ]
        },
        {
          id: 13,
          label: '上行通道 衰减器1',
          packageCode: '613-解调器-通道板参数控制-上行通道衰减器1',
          nmcPackageGridValues: [
            {
              gridCode: '613-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator5 * 100, 4)
            }
          ]
        },
        {
          id: 14,
          label: '上行通道 衰减器2',
          packageCode: '614-解调器-通道板参数控制-上行通道衰减器2',
          nmcPackageGridValues: [
            {
              gridCode: '614-参数值',
              packageGridValue: this.decToHex(this.formc.attenuator6 * 100, 4)
            }
          ]
        }
      ]
      let data = optionsA.find(i => i.id == val)
      let temp = {
        channelCode: '群解调',
        packageCode: data.packageCode,
        nmcPackageGridValues: data.nmcPackageGridValues
      }
      if (temp.nmcPackageGridValues[0]) {
        if (!temp.nmcPackageGridValues[0].packageGridValue) {
          this.$message.error('请输入参数！')
          console.log(temp, '输入参数')
          return
        }
      }
      httpAction(this.url.sendPackage, temp, 'post').then(res => {
        if (res.success) {
          this.$message.success(res.message)
        } else {
          this.$message.error(res.message)
        }
      })
    },
    decToHex(val, length) {
      console.log(val, '---')
      if (val == '' || val == null || val == undefined) return false
      if (length) {
        return Number(val)
          .toString(16)
          .toUpperCase()
          .padStart(length, 0)
      } else {
        return Number(val)
          .toString(16)
          .toUpperCase()
      }
    },
    handleSendPackage(val) {
      if (val == 'networkControl') {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            let temp = this.ProcessParameters(val)
            httpAction(this.url.sendPackage, temp, 'post').then(res => {
              if (res.success) {
                this.$message.success(res.message)
              } else {
                this.$message.error(res.message)
              }
            })
          } else {
            console.log('error submit!!')
            return false
          }
        })
      }
    },
    ProcessParameters(val) {
      let data = {}
      //网络配置
      if (val == 'networkControl') {
        let { tcpPort, IPaddress, gateway, subnetMask, MACaddress } = this.formB
        data = {
          channelCode: '群解调',
          channelId: '',
          nmcPackageGridValues: [
            {
              gridCode: '616-端口号',
              packageGridValue: tcpPort
                .toString(16)
                .toUpperCase()
                .padStart(4, 0)
            },
            {
              gridCode: '616-ip地址',
              packageGridValue: this.handleFormat(IPaddress, '.')
            },
            {
              gridCode: '616-网关',
              packageGridValue: this.handleFormat(gateway, '.')
            },
            {
              gridCode: '616-子网掩码',
              packageGridValue: this.handleFormat(subnetMask, '.')
            },
            {
              gridCode: '616-mac地址',
              packageGridValue: MACaddress.replace(/[:.：-]/g, '').toUpperCase()
            }
          ],
          packageCode: '616-解调器-网络参数设置'
        }
      }
      return data
    },
    handleFormat(val, symbol) {
      //处理ip、网关、子网掩码、mac地址参数格式
      // IP[0]  IP[1]  IP[2]  IP[3]:
      // Eg: 192.168.1.11
      // 传输：0xC0  0xA8  0x01  0x0B
      let data = ''
      let arr = val.split(symbol)
      arr.forEach(i => {
        data += Number(i)
          .toString(16)
          .toUpperCase()
          .padStart(2, 0)
      })
      return data
    },
    handleStart() {
      // if(!this.testForm.startTdh) {
      //   this.$message.error('请输入通道号!')
      //   return
      // }
      let that = this
      this.$refs.testForm.validate(valid => {
        if (valid) {
          // that.countDown = ''
          let data = {
            endTdh: that.testForm.startTdh,
            startTdh: that.testForm.startTdh,
            symbolRate: that.testForm.symbolRate,
            testMode: '导频模式',
            // errorSourceData: that.testForm.errorSourceData
            errorSourceData: ''
          }
          that.loading = true
          httpAction(that.url.add, data, 'post').then(res => {
            if (res.success) {
              that.$message.success(res.message)
              that.loading = false
              that.countDown = 60
              that.testBtnDisabled = true
              // 这里是“测试时长60s，自动结束”的逻辑
              let timerId = setInterval(() => {
                if (that.countDown > 0) {
                  that.countDown--
                } else {
                  clearInterval(timerId)
                  that.testBtnDisabled = false
                }
              }, 1000)
            } else {
              that.$message.error(res.message)
              that.loading = false
            }
          })
        }
      })
      //  // 这里是“测试时长60s，自动结束”的逻辑
      //     let timerId = setInterval(() => {
      //       if(that.countDown > 0) {
      //         that.countDown --
      //       }else {
      //         clearInterval(timerId)
      //         that.testBtnDisabled = false
      //       }
      //     },1000)
    },
    onStart() {
      let params = {
        id: 1,
        active: '主'
      }
      postAction(this.url.edit, params).then(res => {
        if (res.success) {
          this.$message.success('启动成功')
          this.getList()
          this.xxslSubmit()
        } else {
          this.$message.success(res.message)
        }
      })
    },
    getList() {
      getAction(this.url.list).then(res => {
        if (res.success) {
          let info = res.result.records[0]
          this.startBtnDisabled = info.active == '主' ? true : false
        }
      })
    },
    // websocketOnmessage: function(e) {
    //   // console.log('-----接收消息-------', e)
    //   var data = eval('(' + e.data + ')') //解析对象
    //   this.$store.state.user.websocketMsg = JSON.stringify(data)
    //   console.log('-----接收消息999999-------', data)
    // },
    //点击速率下发
    xxslSubmit() {
      this.datalist.sort((a, b) => a.tdh - b.tdh)
      let slList = this.datalist.map(item => item.sl)
      let slStr = slList.join('')
      let hexString = `0x080032${slStr}`
      getAction(this.url.modifySl, { hexString: slStr }).then(res => {
        if (res.success) {
          this.getListData()
        } else {
          // this.$message.error(res.message)
        }
      })
    },
    getListData() {
      getAction(this.url.rateList, { pageSizie: 380 }).then(res => {
        if (res.success) {
          this.datalist = res.result.records || []
          this.datalist = this.datalist.map(item => {
            item.editState = false
            return item
          })
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.groupDemodulatorBox {
  display: flex;
  flex-wrap: wrap;
  border: 3px solid #17dcff;
  .groupDemodulatorBox_card {
    width: 100%;
    display: flex;
    justify-content: space-evenly;
  }
  .cardItem {
    border-right: 3px solid #17dcff;
    border-bottom: 3px solid #17dcff;
    width: 50%;
  }
  .testCard {
    font-size: 18px;
    display: flex;
    justify-content: start;
    .testCard_item {
      display: flex;
      align-items: center; /* 垂直居中 */
      justify-content: center; /* 水平居中（可选） */
    }
  }
}
::v-deep #spsInput {
  border: 0px !important;
}
</style>
